package com.xiaoshuaila.settings.web.controller;

import com.xiaoshuaila.settings.domain.user;
import com.xiaoshuaila.settings.service.userserviceImpl;
import com.xiaoshuaila.settings.service.userservice;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import com.xiaoshuaila.tool.*;

import java.util.HashMap;
import java.util.Map;

public class userServlet extends HttpServlet {
    public userServlet() {
        super();
    }

    protected void doPost(HttpServletRequest request,
                          HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request,
                         HttpServletResponse response) throws ServletException, IOException {
        String path=request.getServletPath();
        if ("/setting/user/save.do".equals(path))
        {
            user user=new user();
            user.setLoginAct(request.getParameter("loginAct"));
            user.setLoginPwd(MD5Util.getMD5(request.getParameter("loginPwd")));
            user.setAllowIps(request.getRemoteAddr());
            System.out.println(request.getRemoteAddr());
            userservice userservice=
                    (com.xiaoshuaila.settings.service.userservice) ServiceFactory.getService(new userserviceImpl());
            user login= null;
            try {
                login = userservice.login(user);
                request.getSession().setAttribute("user",login);
                PrintJson.printJsonFlag(response,true);
            } catch (com.xiaoshuaila.exception.loginexception loginexception) {
                Map map=new HashMap();
                map.put("success",false);
                map.put("msg",loginexception.getMessage());
                PrintJson.printJsonObj(response,map);
            }
            System.out.println("lala");
        }else if ("/setting/user/save.do".equals(path));
    }
}
